<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card class="tree-card">
        <!-- 用了一个行列布局显示头部公司信息 -->
        <add-tree :node-data="compy" />
        <hr>
        <el-tree
          :data="depts"
          :props="{ label: 'name' }"
          default-expand-all
        >
          <template #default="{data}">
            <add-tree
              :node-data="data"
              @showdialogVisible="showdialogVisible"
              @pullDepartment="pullDepartment"
              @edit="edit"
            /></template>
        </el-tree>
      </el-card>
      <add-dept
        ref="dept"
        :showdialog-visible="dialogVisible"
        :node-data="nodeData"
        @pullDepartment="pullDepartment"
        @hidden="hidden"
      />
    </div>
  </div>
</template>

<script>
import addTree from './component/add-tree.vue'
import { getDepartment } from '@/api/department'
import { getChildren } from '@/utils/getDepartmentChildren'
import AddDept from './component/add-dept.vue'
export default {
  components: { addTree, AddDept },
  data() {
    return {
      compy: { name: '江苏传智播客教育科技股份有限公司 ', manager: '负责人', string: true },
      depts: [
      ],
      dialogVisible: false,
      nodeData: {}
    }
  },
  created() {
    this.pullDepartment()
  },
  methods: {
    showdialogVisible(v) {
      this.dialogVisible = true
      this.nodeData = v
    },
    hidden() {
      this.dialogVisible = false
    },
    async pullDepartment() {
      const { depts } = await getDepartment()
      this.depts = getChildren(depts, '')
    },
    edit(val) {
      this.dialogVisible = true
      this.$refs.dept.render(val)
    }
  }
}
</script>

<style scoped>
.tree-card {
  padding: 30px 140px;
  font-size: 14px;
}
</style>
